package handler

import (
	"design-flows/models"
	"design-flows/pkg"

	"github.com/gin-gonic/gin"
)

func Register(c *gin.Context) {
	username := c.PostForm("username")
	password := c.PostForm("password")
	tel := c.PostForm("tel")

	if len(tel) == 11 {
		c.JSON(200, gin.H{
			"code": "500",
			"msg":  "手机号必须是11位",
		})
		return
	}
	data := models.User{
		Username: username,
		Password: pkg.Md5(password),
		Tel:      tel,
	}

	err := models.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": "500",
			"msg":  "注册失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": "200",
		"msg":  "注册成功",
	})
	return

}
